import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreModuleService extends BaseService<any> {
  private readonly logger = new Logger(CoreModuleService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getModuleList
   * 对应 PHP: CoreModuleService_core::getModuleList()
   * 逻辑类型: undefined - undefined
   */
  async getModuleList() {
    // 基于PHP真实逻辑: getModuleList
    // PHP原文: $params = [             'code' => $this->code,             'secret' => $this->secret,             'product_key' => self::PRODUCT         ];         re...
const params = [
            code: this.code,
            secret: this.secret,
            product_key: self.PRODUCT
        ];
        return this.httpGet('member_app_all', params);
    }

    async getIndexModuleLabelList()
    {
        const params = [
            code: this.code,
            secret: this.secret,
        ];
        return this.httpGet('store/label/all', params);
    }

    async getIndexModuleList(label_id)
    {
        const params = [
            code: this.code,
            secret: this.secret,
            labels: [ label_id ],
            order_field: 'sale_num desc, visit_num desc',
            recommend_type:'PHP'
        ];
        return this.httpGet('store/saas/app', params);
    }

    async getIndexAdvList()
    {
        const params = [
            code: this.code,
            secret: this.secret,
            recommend_type:'PHP'
        ];
        return this.httpGet('promotion_adv', params);
    }

    /**
     * 授权信息
     * @return array|Collection|Response|object|ResponseInterface|string
     * @throws GuzzleBusinessException
     */
    async getAuthInfo()
    {
        const params = [
            app_type: '',
            code: this.code,
            secret: this.secret
        ];
        return this.httpGet('member_app', params);
    }

    /**
     * 版本下载
     * @param app_key
     * @param dir
     * @return string|void
     * @throws GuzzleBusinessException
     */
    async downloadModule(app_key, dir)
    {
        if (!is_dir(dir) && !mkdir(dir, 0777, true) && !is_dir(dir)) {
            throw new RuntimeBusinessException(sprintf('Directory "%s" was not created', dir)];
  }

  /**
   * getIndexModuleLabelList
   * 对应 PHP: CoreModuleService_core::getIndexModuleLabelList()
   * 逻辑类型: undefined - undefined
   */
  async getIndexModuleLabelList() {
    // 基于PHP真实逻辑: getIndexModuleLabelList
    // PHP原文: $params = [             'code' => $this->code,             'secret' => $this->secret,         ];         return $this->httpGet('store/label/all', $par...
const params = [
            code: this.code,
            secret: this.secret,
        ];
        return this.httpGet('store/label/all', params);
    }

    async getIndexModuleList(label_id)
    {
        const params = [
            code: this.code,
            secret: this.secret,
            labels: [ label_id ],
            order_field: 'sale_num desc, visit_num desc',
            recommend_type:'PHP'
        ];
        return this.httpGet('store/saas/app', params);
    }

    async getIndexAdvList()
    {
        const params = [
            code: this.code,
            secret: this.secret,
            recommend_type:'PHP'
        ];
        return this.httpGet('promotion_adv', params);
    }

    /**
     * 授权信息
     * @return array|Collection|Response|object|ResponseInterface|string
     * @throws GuzzleBusinessException
     */
    async getAuthInfo()
    {
        const params = [
            app_type: '',
            code: this.code,
            secret: this.secret
        ];
        return this.httpGet('member_app', params);
    }

    /**
     * 版本下载
     * @param app_key
     * @param dir
     * @return string|void
     * @throws GuzzleBusinessException
     */
    async downloadModule(app_key, dir)
    {
        if (!is_dir(dir) && !mkdir(dir, 0777, true) && !is_dir(dir)) {
            throw new RuntimeBusinessException(sprintf('Directory "%s" was not created', dir)];
  }

  /**
   * getIndexModuleList
   * 对应 PHP: CoreModuleService_core::getIndexModuleList()
   * 逻辑类型: undefined - undefined
   */
  async getIndexModuleList(label_id: any) {
    // 基于PHP真实逻辑: getIndexModuleList
    // PHP原文: $params = [             'code' => $this->code,             'secret' => $this->secret,             'labels' => [ $label_id ],             'order_field'...
const params = [
            code: this.code,
            secret: this.secret,
            labels: [ label_id ],
            order_field: 'sale_num desc, visit_num desc',
            recommend_type:'PHP'
        ];
        return this.httpGet('store/saas/app', params);
    }

    async getIndexAdvList()
    {
        const params = [
            code: this.code,
            secret: this.secret,
            recommend_type:'PHP'
        ];
        return this.httpGet('promotion_adv', params);
    }

    /**
     * 授权信息
     * @return array|Collection|Response|object|ResponseInterface|string
     * @throws GuzzleBusinessException
     */
    async getAuthInfo()
    {
        const params = [
            app_type: '',
            code: this.code,
            secret: this.secret
        ];
        return this.httpGet('member_app', params);
    }

    /**
     * 版本下载
     * @param app_key
     * @param dir
     * @return string|void
     * @throws GuzzleBusinessException
     */
    async downloadModule(app_key, dir)
    {
        if (!is_dir(dir) && !mkdir(dir, 0777, true) && !is_dir(dir)) {
            throw new RuntimeBusinessException(sprintf('Directory "%s" was not created', dir)];
  }

  /**
   * getIndexAdvList
   * 对应 PHP: CoreModuleService_core::getIndexAdvList()
   * 逻辑类型: undefined - undefined
   */
  async getIndexAdvList() {
    // 基于PHP真实逻辑: getIndexAdvList
    // PHP原文: $params = [             'code' => $this->code,             'secret' => $this->secret,             'recommend_type'=>'PHP'         ];         return $t...
const params = [
            code: this.code,
            secret: this.secret,
            recommend_type:'PHP'
        ];
        return this.httpGet('promotion_adv', params);
    }

    /**
     * 授权信息
     * @return array|Collection|Response|object|ResponseInterface|string
     * @throws GuzzleBusinessException
     */
    async getAuthInfo()
    {
        const params = [
            app_type: '',
            code: this.code,
            secret: this.secret
        ];
        return this.httpGet('member_app', params);
    }

    /**
     * 版本下载
     * @param app_key
     * @param dir
     * @return string|void
     * @throws GuzzleBusinessException
     */
    async downloadModule(app_key, dir)
    {
        if (!is_dir(dir) && !mkdir(dir, 0777, true) && !is_dir(dir)) {
            throw new RuntimeBusinessException(sprintf('Directory "%s" was not created', dir)];
  }

  /**
   * getAuthInfo
   * 对应 PHP: CoreModuleService_core::getAuthInfo()
   * 逻辑类型: undefined - undefined
   */
  async getAuthInfo() {
    // 基于PHP真实逻辑: getAuthInfo
    // PHP原文: $params = [             'app_type' => '',             'code' => $this->code,             'secret' => $this->secret         ];         return $this->ht...
const params = [
            app_type: '',
            code: this.code,
            secret: this.secret
        ];
        return this.httpGet('member_app', params);
    }

    /**
     * 版本下载
     * @param app_key
     * @param dir
     * @return string|void
     * @throws GuzzleBusinessException
     */
    async downloadModule(app_key, dir)
    {
        if (!is_dir(dir) && !mkdir(dir, 0777, true) && !is_dir(dir)) {
            throw new RuntimeBusinessException(sprintf('Directory "%s" was not created', dir)];
  }

  /**
   * downloadModule
   * 对应 PHP: CoreModuleService_core::downloadModule()
   * 逻辑类型: undefined - undefined
   */
  async downloadModule(app_key: any, dir: any) {
    // 基于PHP真实逻辑: downloadModule
    // PHP原文: if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {             throw new RuntimeException(sprintf('Directory "%s" was not created', $di...
if (!is_dir(dir) && !mkdir(dir, 0777, true) && !is_dir(dir)) {
            throw new RuntimeBusinessException(sprintf('Directory "%s" was not created', dir)];
  }

  /**
   * upgrade
   * 对应 PHP: CoreModuleService_core::upgrade()
   * 逻辑类型: undefined - undefined
   */
  async upgrade(app_key: any, version_id: any) {
    // 基于PHP真实逻辑: upgrade
    // PHP原文: }      /**      * 操作token      * @param $action      * @param $data      * @return array|\core\util\niucloud\Response|object|ResponseInterface      * ...
}

    /**
     * 操作token
     * @param action
     * @param data
     * @return array|\core\util\niucloud\Response|object|ResponseInterface
     * @throws GuzzleBusinessException
     */
    async getActionToken(action, data)
    {
        return this.httpGet('member_app_action/' . action, data);
    }

    /**
     * 获取升级内容
     * @param data
     * @return array|\core\util\niucloud\Response|object|ResponseInterface
     * @throws GuzzleBusinessException
     */
    async getUpgradeContent(data)
    {
        return this.httpGet('member_app_upgrade/content', data);
    }

    /**
     * 校验key是否被占用
     * @param key
     * @return array|Response|object|ResponseInterface
     * @throws GuzzleBusinessException
     */
    async checkKey(key)
    {
        return this.httpGet('store/app_check/' . key, [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取框架最新版本
     * @return array|\core\util\niucloud\Response|object|ResponseInterface
     * @throws GuzzleBusinessException
     */
    async getFrameworkLastVersion()
    {
        return this.httpGet('store/framework/lastversion', [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取框架版本更新记录
     * @return false|mixed
     * @throws GuzzleBusinessException
     */
    async getFrameworkVersionList()
    {
        return this.httpGet('store/framework/version', [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取应用/插件的版本更新记录
     * @return false|mixed
     * @throws GuzzleBusinessException
     */
    async getAppVersionList(app_key)
    {
        return this.httpGet('store/app_version/list', [ product_key: self.PRODUCT, app_key: app_key ))[ 'data' ] || false;
    }
}
  }

  /**
   * getActionToken
   * 对应 PHP: CoreModuleService_core::getActionToken()
   * 逻辑类型: undefined - undefined
   */
  async getActionToken(action: any, data: any) {
    // 基于PHP真实逻辑: getActionToken
    // PHP原文: return $this->httpGet('member_app_action/' . $action, $data);     }      /**      * 获取升级内容      * @param $data      * @return array|\core\util\niuclou...
return this.httpGet('member_app_action/' . action, data);
    }

    /**
     * 获取升级内容
     * @param data
     * @return array|\core\util\niucloud\Response|object|ResponseInterface
     * @throws GuzzleBusinessException
     */
    async getUpgradeContent(data)
    {
        return this.httpGet('member_app_upgrade/content', data);
    }

    /**
     * 校验key是否被占用
     * @param key
     * @return array|Response|object|ResponseInterface
     * @throws GuzzleBusinessException
     */
    async checkKey(key)
    {
        return this.httpGet('store/app_check/' . key, [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取框架最新版本
     * @return array|\core\util\niucloud\Response|object|ResponseInterface
     * @throws GuzzleBusinessException
     */
    async getFrameworkLastVersion()
    {
        return this.httpGet('store/framework/lastversion', [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取框架版本更新记录
     * @return false|mixed
     * @throws GuzzleBusinessException
     */
    async getFrameworkVersionList()
    {
        return this.httpGet('store/framework/version', [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取应用/插件的版本更新记录
     * @return false|mixed
     * @throws GuzzleBusinessException
     */
    async getAppVersionList(app_key)
    {
        return this.httpGet('store/app_version/list', [ product_key: self.PRODUCT, app_key: app_key ))[ 'data' ] || false;
    }
}
  }

  /**
   * getUpgradeContent
   * 对应 PHP: CoreModuleService_core::getUpgradeContent()
   * 逻辑类型: undefined - undefined
   */
  async getUpgradeContent(data: any) {
    // 基于PHP真实逻辑: getUpgradeContent
    // PHP原文: return $this->httpGet('member_app_upgrade/content', $data);     }      /**      * 校验key是否被占用      * @param $key      * @return array|Response|object|R...
return this.httpGet('member_app_upgrade/content', data);
    }

    /**
     * 校验key是否被占用
     * @param key
     * @return array|Response|object|ResponseInterface
     * @throws GuzzleBusinessException
     */
    async checkKey(key)
    {
        return this.httpGet('store/app_check/' . key, [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取框架最新版本
     * @return array|\core\util\niucloud\Response|object|ResponseInterface
     * @throws GuzzleBusinessException
     */
    async getFrameworkLastVersion()
    {
        return this.httpGet('store/framework/lastversion', [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取框架版本更新记录
     * @return false|mixed
     * @throws GuzzleBusinessException
     */
    async getFrameworkVersionList()
    {
        return this.httpGet('store/framework/version', [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取应用/插件的版本更新记录
     * @return false|mixed
     * @throws GuzzleBusinessException
     */
    async getAppVersionList(app_key)
    {
        return this.httpGet('store/app_version/list', [ product_key: self.PRODUCT, app_key: app_key ))[ 'data' ] || false;
    }
}
  }

  /**
   * checkKey
   * 对应 PHP: CoreModuleService_core::checkKey()
   * 逻辑类型: undefined - undefined
   */
  async checkKey(key: any) {
    // 基于PHP真实逻辑: checkKey
    // PHP原文: return $this->httpGet('store/app_check/' . $key, [ 'product_key' => self::PRODUCT ])[ 'data' ] ?? false;     }      /**      * 获取框架最新版本      * @return...
return this.httpGet('store/app_check/' . key, [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取框架最新版本
     * @return array|\core\util\niucloud\Response|object|ResponseInterface
     * @throws GuzzleBusinessException
     */
    async getFrameworkLastVersion()
    {
        return this.httpGet('store/framework/lastversion', [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取框架版本更新记录
     * @return false|mixed
     * @throws GuzzleBusinessException
     */
    async getFrameworkVersionList()
    {
        return this.httpGet('store/framework/version', [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取应用/插件的版本更新记录
     * @return false|mixed
     * @throws GuzzleBusinessException
     */
    async getAppVersionList(app_key)
    {
        return this.httpGet('store/app_version/list', [ product_key: self.PRODUCT, app_key: app_key ))[ 'data' ] || false;
    }
}
  }

  /**
   * getFrameworkLastVersion
   * 对应 PHP: CoreModuleService_core::getFrameworkLastVersion()
   * 逻辑类型: undefined - undefined
   */
  async getFrameworkLastVersion() {
    // 基于PHP真实逻辑: getFrameworkLastVersion
    // PHP原文: return $this->httpGet('store/framework/lastversion', [ 'product_key' => self::PRODUCT ])[ 'data' ] ?? false;     }      /**      * 获取框架版本更新记录      * @...
return this.httpGet('store/framework/lastversion', [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取框架版本更新记录
     * @return false|mixed
     * @throws GuzzleBusinessException
     */
    async getFrameworkVersionList()
    {
        return this.httpGet('store/framework/version', [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取应用/插件的版本更新记录
     * @return false|mixed
     * @throws GuzzleBusinessException
     */
    async getAppVersionList(app_key)
    {
        return this.httpGet('store/app_version/list', [ product_key: self.PRODUCT, app_key: app_key ))[ 'data' ] || false;
    }
}
  }

  /**
   * getFrameworkVersionList
   * 对应 PHP: CoreModuleService_core::getFrameworkVersionList()
   * 逻辑类型: undefined - undefined
   */
  async getFrameworkVersionList() {
    // 基于PHP真实逻辑: getFrameworkVersionList
    // PHP原文: return $this->httpGet('store/framework/version', [ 'product_key' => self::PRODUCT ])[ 'data' ] ?? false;     }      /**      * 获取应用/插件的版本更新记录      * @...
return this.httpGet('store/framework/version', [ product_key: self.PRODUCT ))[ 'data' ] || false;
    }

    /**
     * 获取应用/插件的版本更新记录
     * @return false|mixed
     * @throws GuzzleBusinessException
     */
    async getAppVersionList(app_key)
    {
        return this.httpGet('store/app_version/list', [ product_key: self.PRODUCT, app_key: app_key ))[ 'data' ] || false;
    }
}
  }

  /**
   * getAppVersionList
   * 对应 PHP: CoreModuleService_core::getAppVersionList()
   * 逻辑类型: undefined - undefined
   */
  async getAppVersionList(app_key: any) {
    // 基于PHP真实逻辑: getAppVersionList
    // PHP原文: return $this->httpGet('store/app_version/list', [ 'product_key' => self::PRODUCT, 'app_key' => $app_key ])[ 'data' ] ?? false;     } }...
return this.httpGet('store/app_version/list', [ product_key: self.PRODUCT, app_key: app_key ))[ 'data' ] || false;
    }
}
  }
}
